package org.bean;

import java.util.LinkedList;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

/**
 * @author : DengYing
 * @CreateDate : 2017年9月13日 下午3:55:53
 * @Description ：世界聊天房间
 */
public class ChatRoom {
	private int id;
	
	/** 房间成员 */
	private Set<Integer> pids = Sets.newHashSet();
	/** 聊天缓存 */
	private LinkedList<SourceChatMsg> msgCache = new LinkedList<>();

	public ChatRoom(){
	}
	
	public ChatRoom(int id) {
		super();
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public Set<Integer> getPids() {
		return pids;
	}
	

	public LinkedList<SourceChatMsg> getMsgCache() {
		return msgCache;
	}

	public void setMsgCache(LinkedList<SourceChatMsg> msgCache) {
		this.msgCache = msgCache;
	}

	public void addPid(Integer pid) {
		pids.add(pid);
	}

	public void remove(Integer pid) {
		pids.remove(pid);
	}
	
	public void addMsg(SourceChatMsg msg){
		if (msgCache.size() >= 10) {
			msgCache.poll();
		}
		msgCache.offer(msg);
	}
	
	public LinkedList<SourceChatMsg> getAllMsg(){
		return msgCache;
	}
}
